﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace CustomControlLibrary
{
    public partial class StmProcessBar : Form
    {
        private static StmProcessBar instance = new StmProcessBar();
        private bool _altF4Pressed = false;

        public StmProcessBar()
        {
            InitializeComponent();
        }

        public static StmProcessBar Instance
        {
            get
            {
                return instance;
            }
        }

        /// <summary>
        /// Handle form closing event: Prevent user close process bar
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SmProcessBar_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (_altF4Pressed)
            {
                if (e.CloseReason == CloseReason.UserClosing)
                {
                    e.Cancel = true;
                }
                _altF4Pressed = false;
            }
        }

        /// <summary>
        /// Handle keydown event: Detect when user press Alt + F4
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void StmProcessBar_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Alt && e.KeyCode == Keys.F4)
                _altF4Pressed = true;
        }
    }
}
